package com.ease.access.systemmonitor.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ease.access.systemmonitor.service.DbTableSpaceAccessService;
import com.ease.business.systemmonitor.util.MapUtil;
import com.ease.common.vo.MapParameter;
import com.ease.model.systemmonitor.DbTableSpace;
import com.ease.platform.access.service.impl.AbstractJdbcTemplateAccessServiceImpl;

@Deprecated
/*
 * 请继承 AbstractParameterizedBeanJdbcTemplateAccessServiceImpl sql写在对应的文件里，参考DatabaseTable和DatabaseTable.statement.xml里
 */
public class DbTableSpaceAccessServiceImpl extends AbstractJdbcTemplateAccessServiceImpl implements DbTableSpaceAccessService {

	public List<DbTableSpace> findAllDbTableSpaceInfo(Object obj) {
		String sql = "SELECT A.TABLESPACE_NAME TABLESPACENAME,A.BYTES/1024/1024 TOTALSUM,(A.BYTES-B.BYTES)/1024/1024 USETOTAL,B.BYTES/1024/1024 FREETOTAL,"
				+ " round(((a.bytes-b.bytes)/a.bytes)*100,2) USEAGE  FROM (SELECT TABLESPACE_NAME,SUM(BYTES) BYTES FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) A,"
				+ " (SELECT TABLESPACE_NAME,SUM(BYTES) BYTES, MAX(BYTES) LARGEST FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) B "
				+ " WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME  ORDER BY ((A.BYTES-B.BYTES)/A.BYTES) DESC ";
		MapParameter parameter = new MapParameter();
		List<Map<String, Object>> resultList = this.getJdbcTemplateDataAccessObject().find(sql, parameter);
		List<DbTableSpace> listDbTableSpace = new ArrayList<DbTableSpace>();
		if (listDbTableSpace != null)
			for (int i = 0; i < resultList.size(); i++) {
				HashMap<String, Object> map = (HashMap<String, Object>) resultList.get(i);
				DbTableSpace bean = new DbTableSpace();
				bean.setTableSpaceNmae(MapUtil.getStr(map, "TABLESPACENAME"));
				bean.setTotalSum(MapUtil.getStr(map, "TOTALSUM"));
				bean.setUseTotal(MapUtil.getStr(map, "USETOTAL"));
				bean.setFreeTotal(MapUtil.getStr(map, "FREETOTAL"));
				bean.setUseAge(MapUtil.getStr(map, "USEAGE"));
				listDbTableSpace.add(bean);
			}
		return listDbTableSpace;
	}

}
